﻿package com.ufenlei.LTS{
	import flash.events.Event;
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.geom.Point;
	import flash.geom.Matrix;
	import flash.filters.BlurFilter;

	public class BlackShadow extends Sprite {
		var father:Sprite;
		var openOrclose:String;
		var i:int;
		var myMatrix:Matrix;
		public function BlackShadow(fa:Sprite,sWidth:int,sHeight:int,oc:String = "close"):void{ 
			openOrclose = oc;
			father = fa;
			var shadowWidth:int = sWidth;
			var shadowHeight:int = sHeight;
			var point:Point = new Point(sWidth/2,sHeight/2);
			var matrix:Matrix = new Matrix();
			matrix.transformPoint(point);
			this.transform.matrix = matrix;
			var roundRect:Shape = new Shape();
			roundRect.graphics.beginFill(0X000000,0.5);
			roundRect.graphics.drawRoundRect(0,0,shadowWidth,shadowHeight,10,10);
			roundRect.graphics.endFill();
			var blur:BlurFilter = new BlurFilter();
			blur.blurX = 5;
			blur.blurY = 5;
			roundRect.filters = [blur];
			this.addChild(roundRect);
			if (openOrclose == "close") {
				i = 20;
				father.addChild(this);
				this.addEventListener(Event.ENTER_FRAME, disappear);
			} else if (openOrclose == "open") {
				i = 0;
				father.addChild(this);
				this.scaleY = 0;
				this.addEventListener(Event.ENTER_FRAME, appear);
			}
			myMatrix = roundRect.transform.matrix;
			var tempx:Number;
			var tempy:Number;
			tempx = this.x+this.width/2;
			tempy = this.y+this.height/2;
			myMatrix.translate(-tempx,-tempy);
			roundRect.transform.matrix=myMatrix;
		}
		private function disappear(evt:Event):void {
			if (i>0) {
				i--;
				this.scaleX = 0.05*i;
				this.scaleY = 0.05*i;
				this.alpha = 0.05*i;
			} else {
				father.removeChild(this);
				this.removeEventListener(Event.ENTER_FRAME, disappear);
			}
		}
		private function appear(evt:Event):void {
			if (i<20) {
				i++;
				this.scaleX = 0.05*i;
				this.scaleY = 0.05*i;
				this.alpha = 0.05*i;
			} else {
				var openEvent:Event = new Event("Shadow_OPEN");
				this.dispatchEvent(openEvent);
				father.removeChild(this);
				this.removeEventListener(Event.ENTER_FRAME, appear);
			}
		}
	}
}